package com.codingvip;

/**
 * @Author Tony.Han
 * @Created at 2020/4/9 10:53 上午
 * Desc:
 */
public class MySqrt {
    int s;

    public Double mySqrt(int x) {
        s=x;
        if (x == 0) {
            return Double.valueOf(Integer.valueOf(x));
        }
        return sqrt(x);
    }

    private Double sqrt(double x) {
        double result = (x + s / x) / 2;
        if (result == x) {
            return result;
        }else{
            return sqrt(result);
        }
    }

    public static void main(String[] args) {
        MySqrt mySqrt = new MySqrt();
        Double result=mySqrt.mySqrt(3);
        System.out.println("------------"+result);
    }
}
